package com.financing.wap.web.controller.api;

import com.financing.wap.common.BizEnums;
import com.financing.wap.common.CommonConstantUtil;
import com.financing.wap.common.Pager;
import com.financing.wap.common.ResultMap;
import com.financing.wap.common.SessionUtil;
import com.financing.wap.dao.wherecondition.WC;
import com.financing.wap.dao.wherecondition.WhereCondition;
import com.financing.wap.dto.*;
import com.financing.wap.service.*;
import com.financing.wap.util.Constants;
import com.financing.wap.util.DTOdateSetUtil;
import com.financing.wap.util.HttpClientUtil;
import com.financing.wap.util.PropertiesUtils;
import com.financing.wap.util.StringUtil;
import com.financing.wap.util.TimesUtil;
import com.financing.wap.vo.OrderCountVO;
import com.financing.wap.vo.OrderDoneCountDto;
import com.financing.wap.vo.OrderResVO;
import com.financing.wap.vo.OrderResultVO;
import com.financing.wap.util.AjaxUtils;
import com.financing.wap.web.controller.BaseController;
import com.mysql.jdbc.TimeUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller("fpPhoneClientController")
@RequestMapping("/api/fpPhoneClient")
public class FpPhoneClientController extends BaseController  { 

	private Logger logger = Logger.getLogger(getClass());

	@Autowired
	private IFpPhoneClientService fpPhoneClientService;

	@Autowired
	private IFpClientActivityService fpClientActivityService;

	@Autowired
	private IUserWechatService userWehatService;

	@Autowired
	private IOrderService orderService;

	@Autowired
	private IFpShopUserRelProductService fpShopUserRelProductService;

	@Autowired
	private IUserInfoService userInfoService;

	@Autowired
	private IUserService userService;
	

	@Autowired
	private IShopperUserInfoService shopperUserInfoService;

	@Autowired
	private IFpFaUserContractService fpFaUserContractService;//合同service

	@Autowired
	private IProductOrderDataService  productOrderDataService ;

	private String shopViewCount = "wapData/shopViewCount?shopId={0}";


	private String shopProductRecordDetail = "wapData/shopProductRecordDetail?shopId={0}&param={1}&pageSize={2}&pageNo={3}&monthStart={4}";

	private String shopRecord="wapData/shopRecord?shopId={0}&pageSize={1}&pageNo={2}";

	private String wapData="wapData/shopUserRecordDetail?shopId={0}&wechatId={1}&pageSize={2}&pageNo={3}";


	//查询店铺首页new 访客数
	private String shopView="wapData/shopViewCountAll?shopId={0}";

	//查询浏览量
	private String shopSee = "wapData/shopSeeCount?shopId={0}&monthStart={1}";
	//查询产品浏览量
	private String shopProductSee = "wapData/shopProductCount?shopId={0}&monthStart={1}&pageNo={2}&pageSize={3}";

	//某店铺 以产品为维度     统计浏览量和访客数 ，分享数    20180425备注   以分享为主
	private String shareAndSeeProduct = "wapData/shopShareProductCount?shopId={0}&monthStart={1}&pageNo={2}&pageSize={3}";

	//产品分享次数
	private String shareShopProductCount = "wapData/shareShopProductCount?shopId={0}&monthStart={1}&pageNo={2}&pageSize={3}&param={4}";

	//产品查看详情
	private String shopProductSeeDetail = "wapData/shopProductSeeDetail?shopId={0}&monthStart={1}&pageNo={2}&pageSize={3}&param={4}";

	@Autowired
	private IProductService productService;

	@Autowired
	private IFpFundInfoService fpFundInfoService;

	@Autowired
	private IFpClientOrderService fpClientOrderService;

	/**
	 * 店铺首页访问量 new
	 * @throws SQLException 
	 */
	@RequestMapping("/productViewCont")
	@ResponseBody
	public ResultMap productViewCont(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient,Pager pager) {
		ResultMap result = new ResultMap();
		try{
			UserDTO user = SessionUtil.getSession().getUser();
			String phone=user.getLoginName();
			SimpleDateFormat smp = new SimpleDateFormat("yyyy-MM-dd");
			//查询预约统计 
			//查询当日预约金额
			Double nowDate =0.0;

			//预约金额 按产品统计  金额倒叙
			OrderDTO orders = new OrderDTO();
			orders.setShopperId(phone);  //店铺关联
			orders.setCreateDateStr(smp.format(new Date()));
			orders.setNoStatus("999");  //不包含 
			List<OrderCountVO> ov = orderService.orderListCount(orders);	
			for (int i = 0; i < ov.size(); i++) {
				nowDate+=ov.get(i).getCount();
			}

			//查询当月
			Double monthCount  =0.0;
			orders.setCreateDateStr(smp.format(TimesUtil.getTimesMonthmorning()));
			orders.setNoStatus("999");  //不包含 
			List<OrderCountVO> ovs = orderService.orderListCount(orders);	
			for (int i = 0; i < ovs.size(); i++) {
				monthCount+=ovs.get(i).getCount();
			}


			//查询店铺首页浏览统计
			String format=MessageFormat.format(shopView,phone);
			String u=mongodbUrl+format;
			JSONObject json = getMongoDB(u);
			Map<Object,Object> map = (Map)json;

			//查询自有产品预约 累加
			//			FpClientOrderDTO fpClientOrder = new FpClientOrderDTO();
			//			fpClientOrder.setSearchDate(smp.format(new Date())); 
			//			fpClientOrder.setUserId(phone);  //userId即店铺Id
			//			nowDate += fpClientOrderService.orderContByUserId(fpClientOrder)*10000;   //查询今日
			//			
			//			fpClientOrder.setSearchDate(smp.format(TimesUtil.getTimesMonthmorning())); 
			//			monthCount += fpClientOrderService.orderContByUserId(fpClientOrder) * 10000;   //查询本月
			map.put("nowDateCount", nowDate);
			map.put("monthCount", monthCount);
			result.setAttribute("view",map );

			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

		}catch(Exception e){
			e.printStackTrace();
			log.error("query productViewCont error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}
	SimpleDateFormat smp = new SimpleDateFormat("yyyy-MM-dd");
	/**
	 * 统计访问量与浏览量
	 */
	@RequestMapping("/shopSeeCount")
	@ResponseBody
	public ResultMap shopSeeCount(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient,Pager pager) {
		ResultMap result = new ResultMap();
		try{
			UserDTO user = SessionUtil.getSession().getUser();
			String phone=user.getLoginName();
			String times = request.getParameter("getTimes");  //查询时间 默认为7天 ，不传
			if(!StringUtils.isBlank(times)){
				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(times)));
			}else{
				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(-7)));
			}

			//查询店铺浏览量
			String format=MessageFormat.format(shopSee,phone,times);
			String u=mongodbUrl+format;
			JSONObject json = getMongoDB(u);
			Map<Object,Object> map = (Map)json;


			result.setAttribute("view", map);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
		}catch(Exception e){
			log.error("query shopSeeCount error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}


	/**
	 * 
	 * 产品统计 按时间查询  产品分组
	 */
	@RequestMapping("/productCount")
	@ResponseBody
	public ResultMap productCount(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient,Pager pager){
		ResultMap result = new ResultMap();
		try{
			UserDTO user = SessionUtil.getSession().getUser();
			String phone=user.getLoginName();

			//  判断是否需要查询 多个手机号   有值 就多个
			String isList=request.getParameter("isList");
			if(StringUtils.isNotBlank(isList)){
				String phoneParam=request.getParameter("uPhone");
				String orgId=request.getParameter("orgid");
				if(StringUtils.isNotBlank(phoneParam)){
					phone=phoneParam;
				}
				//如果有机构用户  设置手机号为“”
				if(StringUtil.isNullOrEmptyNStr(orgId)){
					phone="";
				}
				String phoneList=userInfoService.queryPhoneLayerPath(phone,orgId);
				if(StringUtils.isNotBlank(phoneList)){
					phone=phoneList;
				}
			}


			SimpleDateFormat smp = new SimpleDateFormat("yyyy-MM-dd");
			String times = request.getParameter("getTimes");  //查询时间 默认为7天 ，不传
			if(!StringUtils.isBlank(times)){
				if(times.equals("-1")){
					times="";
				}else{
					times= smp.format(TimesUtil.timsUpd(Integer.valueOf(times)));
				}
			}else{
				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(-7)));
			}
			//浏览量  访客数 总数统计  数量倒叙 

			String format=MessageFormat.format(shopProductSee,phone,times,pager.getPageNo(),pager.getPageSize());
			String u=mongodbUrl+format;
			JSONObject json = getMongoDB(u);
			Map<Object,Object> map = (Map)json;
			//取出来取长度 查询 产品信息
			//JSONArray ProductCountView = (JSONArray) map.get("ProductCountView");  //访客量
			JSONArray ProductCountSee = (JSONArray) map.get("ProductCountSee");    //浏览量
			String rm = "";
			for (int i = 0; i < ProductCountSee.size(); i++) {
				JSONObject ps = (JSONObject) ProductCountSee.get(i);
				Object type = ps.get("type");
				Object pId = ps.get("param");
				//查询产品信息
				if(type==null||pId==null||!(pId+"").matches("[0-9\\-a-zA-Z]+")){
					continue;
				}

				if("110204".equals(type)){//基金
					FpFundInfoDTO fund = fpFundInfoService.loadById(Integer.parseInt(pId+""));

					if(fund!=null && fund.getId()!=null){
						logger.info("goto url productName: "+fund.getJjmc());
						ps.put("status", fund.getPubStatus());//1上架 0下架
						ps.put("productName", fund.getJjmc());//1上架 0下架
					}else{
						rm+=","+i;
					}
				}else if("110209".equals(type)){//金策师  自主产品类型
					FpShopUserRelProductDTO dto = fpShopUserRelProductService.loadById(Integer.parseInt(pId+""));
					if(dto!=null && dto.getId()!=null){
						logger.info("goto url productName: "+dto.getProductName());
						ps.put("productName", dto.getProductName());//1上架 0下架
					}else{
						rm+=","+i;
					}
				}else{  //
					String pd = productService.getProductNameByProductCode(pId.toString());
					if(StringUtils.isBlank(pd)){
						rm+=","+i;
					}else{
						ps.put("productName", pd);
					}
				}


			}
			//判断移除
			if(rm.length()>0){
				String[] l = rm.split(",");
				for (int i = (l.length-1); i>=0 ; i--) {
					if(!StringUtils.isBlank(l[i])){
						int index = Integer.valueOf(l[i]);
						ProductCountSee.remove(index);
					}
				}
			}

			result.setAttribute("map", map);

			//预约金额 按产品统计  金额倒叙
			OrderDTO order = new OrderDTO();
			order.setShopperId(phone);  //店铺关联
			order.setCreateDateStr(times);
			order.setNoStatus("999");  //不包含 
			List<OrderCountVO> ov = orderService.orderListCount(order);	
			result.setAttribute("make", ov);

			//打款金额 按产品统计 金额倒叙
			order.setoStatus("220,240,310,320,330,360");
			List<OrderCountVO> done = orderService.orderListCount(order);	
			result.setAttribute("done", done);


			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
		}catch(Exception e){
			log.error("query productCount error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	/**
	 * 
	 * 产品统计 按时间查询  产品分组     20180502 以产品分享为主
	 */
	@RequestMapping("/shareAndSeeProduct")
	@ResponseBody
	public ResultMap shareAndSeeProduct(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient,Pager pager){
		ResultMap result = new ResultMap();
		try{
			UserDTO user = SessionUtil.getSession().getUser();
			String phone=user.getLoginName();

			//  判断是否需要查询 多个手机号   有值 就多个
//			String isList=request.getParameter("isList");
//			if(StringUtils.isNotBlank(isList)){
				String phoneParam=request.getParameter("uPhone");
				String orgId=request.getParameter("orgid");
				if(StringUtils.isNotBlank(phoneParam)){
					phone=phoneParam;
				}
				//如果有机构用户  设置手机号为“”
				if(!StringUtil.isNullOrEmptyNStr(orgId)){
					phone="";
				}
				String phoneList=userInfoService.queryPhoneLayerPath(phone,orgId);
				if(StringUtils.isNotBlank(phoneList)){
					phone=phoneList;
				}
//			}


			SimpleDateFormat smp = new SimpleDateFormat("yyyy-MM-dd");
			String times = request.getParameter("getTimes");  //查询时间 默认为 ，不传默认全部
			if(!StringUtils.isBlank(times)){
				if(times.equals("-1")){
					times="";
				}else{
					times= smp.format(TimesUtil.timsUpd(Integer.valueOf(times)));
				}
			}else{
				//				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(-7)));
				times="";
			}
			//浏览量  访客数 总数统计  数量倒叙 

			String format=MessageFormat.format(shareAndSeeProduct,phone,times,pager.getPageNo(),pager.getPageSize());
			String u=mongodbUrl+format;
			JSONObject json = getMongoDB(u);
			Map<Object,Object> map = (Map)json;
			//取出来取长度 查询 产品信息
			JSONArray productCountShare = (JSONArray) map.get("productCountShare");    //浏览量
			String rm = "";
			for (int i = 0;productCountShare!=null && i < productCountShare.size(); i++) {
				JSONObject ps = (JSONObject) productCountShare.get(i);
				Object type = ps.get("type");
				Object pId = ps.get("param");
				//查询产品信息
				if((type==null&&pId==null)||!(pId+"").matches("[0-9\\-a-zA-Z]+")){
					continue;
				}

				if("110204".equals(type)){//基金
					FpFundInfoDTO fund = fpFundInfoService.loadById(Integer.parseInt(pId+""));

					if(fund!=null && fund.getId()!=null){
						logger.info("goto url productName: "+fund.getJjmc());
						ps.put("status", fund.getPubStatus());//1上架 0下架
						ps.put("productName", fund.getJjmc());//1上架 0下架
					}else{
						rm+=","+i;
					}
				}else if("110209".equals(type)){//金策师  自主产品类型
					FpShopUserRelProductDTO dto = fpShopUserRelProductService.loadById(Integer.parseInt(pId+""));
					if(dto!=null && dto.getId()!=null){
						logger.info("goto url productName: "+dto.getProductName());
						ps.put("productName", dto.getProductName());//1上架 0下架
					}else{
						rm+=","+i;
					}
				}else{  //
					String pd = productService.getProductNameByProductCode(pId.toString());
					if(StringUtils.isBlank(pd)){
						rm+=","+i;
					}else{
						ps.put("productName", pd);
					}
				}


			}
			//判断移除
			if(rm.length()>0){
				String[] l = rm.split(",");
				for (int i = (l.length-1); i>=0 ; i--) {
					if(!StringUtils.isBlank(l[i])){
						int index = Integer.valueOf(l[i]);
						productCountShare.remove(index);
					}
				}
			}

			result.setAttribute("map", map);

			//预约金额 按产品统计  金额倒叙
			OrderDTO order = new OrderDTO();
			order.setShopperId(phone);  //店铺关联
			order.setCreateDateStr(times);
			order.setNoStatus("999");  //不包含 
			List<OrderCountVO> ov = orderService.orderListCount(order);	
			result.setAttribute("make", ov);

			//打款金额 按产品统计 金额倒叙
			order.setoStatus("220,240,310,320,330,360");
			List<OrderCountVO> done = orderService.orderListCount(order);	
			result.setAttribute("done", done);


			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
		}catch(Exception e){
			log.error("query productCount error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	/**
	 * 交易统计 时间分组
	 * 
	 */
	@RequestMapping("/productTimesCount")
	@ResponseBody
	public ResultMap productTimesCount(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient,Pager pager){
		ResultMap result = new ResultMap();
		SimpleDateFormat smp = new SimpleDateFormat("yyyy-MM-dd");
		try{

			UserDTO user = SessionUtil.getSession().getUser();
			String shopperId = user.getLoginName();


			OrderDTO order = new OrderDTO();
			order.setShopperId(shopperId);  //店铺关联
			//默认七天
			String times = request.getParameter("getTimes");  //查询时间 默认为7天 ，不传
			if(!StringUtils.isBlank(times)){
				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(times)));
			}else{
				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(-7)));
			}
			//时间正序
			order.setCreateDateStr(times);
			//预约
			order.setNoStatus("999");
			List<OrderCountVO> make = orderService.orderTimesCount(order);



			Double makeAll=0.0;
			for (int i = 0; i < make.size(); i++) {
				makeAll+=make.get(i).getCount();
			}
			//交易成功220,,310,320,330,360
			order.setoStatus("240");   //只查询确认打款、待佣金到账
			List<OrderCountVO> done = orderService.orderTimesCountDone(order);	
			Double doneAll=0.0;
			for (int i = 0; i < done.size(); i++) {
				doneAll+=done.get(i).getCount();
			}
			result.setAttribute("done", done);
			result.setAttribute("make", make);
			result.setAttribute("makeAll", makeAll);
			result.setAttribute("doneAll", doneAll);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

		}catch(Exception e){
			log.error("query productTimesCount error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	/**
	 * 金策师机构版 - 交易统计 时间分组(7天 1个月 半年 一年 全部)
	 * 
	 * 按机构人员及时间统计预约金额及成交订单
	 */
	@RequestMapping("/productCountByTimeAndOrg")
	@ResponseBody
	public ResultMap productCountByTimeAndOrg(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient,Pager pager){
		ResultMap result = new ResultMap();
		SimpleDateFormat smp = new SimpleDateFormat("yyyy-MM-dd");
		try{

			String uPhone = request.getParameter("uPhone");//机构人员手机
			String orgid = request.getParameter("orgid");//机构ID

			String userids = null; //要查询的人员id集合
			OrderDTO order = new OrderDTO();//订单
			FpManagerOrder fpman = new FpManagerOrder();//订单服务顾问
			if(StringUtils.isBlank(uPhone) && StringUtils.isBlank(orgid)) {
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			} else if(StringUtils.isNotBlank(uPhone) && StringUtils.isNotBlank(orgid)){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_TYPE_ERROR);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			} else {
				if(StringUtils.isNotBlank(orgid) && StringUtils.equals(orgid, "-1")) {//非机构人员 根节点
					orgid = null;
					userids = SessionUtil.getSession().getUser().getId();

					order.setCreateBy(userids);
				} else {
					userids = userInfoService.queryUseridByLayerPath(uPhone, orgid);//机构人员
					if(userids ==null) {
						order.setCreateBy(SessionUtil.getSession().getUser().getId());
					} else {
						if(userids.matches("\\d+")){//如果返回的手机号  需要查询userId
							UserInfoDTO userInfo =  new UserInfoDTO();
							userInfo.setTelePhone(userids);
							userInfo.setDeptflag(BizEnums.DeptType.PERSON);//人员
							userInfo.setStatus(0);
							UserInfoDTO queryUserInfo = userInfoService.queryUserInfo(userInfo);
							fpman.setsUid(queryUserInfo.getUserId());
						}else{
							fpman.setsUid(userids);
						}
					}
				}
			}

			List<String> xAxisDatas = new ArrayList<String>();//横坐标
			//默认七天
			String times = request.getParameter("times");  //查询时间 默认为7天 ，不传

			if(!StringUtils.isBlank(times)){
				if(StringUtils.equals(times, "-1")) {//查全部订单
					order.setIsAll("true");//是否查全部
					times = null;
					xAxisDatas = orderService.queryOrderXaxisDatas(order, fpman);//全部订单查询 - 所有订单时间集合
				} else {
					xAxisDatas = TimesUtil.getTimesData(new Date(), 0-Integer.valueOf(times));
					times= smp.format(TimesUtil.timsUpd(Integer.valueOf(times)));

					order.setCreateDateStr(times);//最小时间
				}
			}else{
				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(-6)));
				xAxisDatas = TimesUtil.getTimesData(new Date(), 6);

				order.setCreateDateStr(times);//最小时间
			}

			//预约订单
			order.setoStatus("110");
			List<OrderCountVO> make = orderService.orderCountByTimeAndOrg(order, fpman);

			//成交订单220,240,310,320,330,360
			order.setoStatus(null);
			order.setAllOrderStatus("220,240,310,320,330,360");
			List<OrderCountVO> done = orderService.orderCountByTimeAndOrg(order, fpman);	


			List<OrderCountVO> makelist = new ArrayList<OrderCountVO>();
			List<OrderCountVO> donelist = new ArrayList<OrderCountVO>();
			if(make.size()>0 || done.size()>0) {
				for(String date : xAxisDatas) {
					//当前坐标日期是否含有预约订单
					boolean ishavemake = false;
					for(OrderCountVO m:make) {
						if(StringUtils.equals(m.getCreateDate(), date)) {
							ishavemake = true;
							makelist.add(m);
							break;
						}
					}
					if(!ishavemake) {
						OrderCountVO emOrder = new OrderCountVO();
						emOrder.setCount(0d);
						emOrder.setCreateDate(date);
						makelist.add(emOrder);
					}

					//当前坐标日期是否含有成交订单
					boolean ishavedone = false;
					for(OrderCountVO d:done) {
						if(StringUtils.equals(d.getCreateDate(), date)) {
							ishavedone = true;
							donelist.add(d);
							break;
						}
					}
					if(!ishavedone) {
						OrderCountVO emOrder = new OrderCountVO();
						emOrder.setCount(0d);
						emOrder.setCreateDate(date);
						donelist.add(emOrder);
					}
				}
			}

			//按订单金额统计订单 100W-300W | 300W-1000W | >=1000W
			{
				List<OrderDoneCountDto> OrderDoneCountDtolist = new ArrayList<OrderDoneCountDto>();

				//100W-300W
				WhereCondition wc = WC.one();
				wc.andGreaterEquals("a.O_AMOUNT", 1000000);
				wc.andLessThan("a.O_AMOUNT", 3000000);
				OrderDoneCountDto orderDoneCount = orderService.queryCountOrderDone(order, fpman, wc);
				orderDoneCount.setCountType("100W-300W");
				OrderDoneCountDtolist.add(orderDoneCount);

				//300W-1000W 
				wc = WC.one();
				wc.andGreaterEquals("a.O_AMOUNT", 3000000);
				wc.andLessThan("a.O_AMOUNT", 10000000);
				orderDoneCount = orderService.queryCountOrderDone(order, fpman, wc);
				orderDoneCount.setCountType("300W-1000W");
				OrderDoneCountDtolist.add(orderDoneCount);

				//>=1000W
				wc = WC.one();
				wc.andGreaterEquals("a.O_AMOUNT", 10000000);
				orderDoneCount = orderService.queryCountOrderDone(order, fpman, wc);
				orderDoneCount.setCountType(">=1000W");
				OrderDoneCountDtolist.add(orderDoneCount);

				result.setAttribute("donecount", OrderDoneCountDtolist);
			}

			Double makeAll=0.0, doneAll=0.0;//总预约订单金额 总成交订单金额
			for (int i = 0; i < makelist.size(); i++) {
				makeAll+=makelist.get(i).getCount();
			}
			for (int i = 0; i < donelist.size(); i++) {
				doneAll+=donelist.get(i).getCount();
			}

			if(StringUtils.equals(request.getParameter("times"), "-1") && donelist.size()==0 && makelist.size()==0) {//全部订单为空 横坐标默认取当前时间往前推一年
				xAxisDatas = TimesUtil.getTimesData(new Date(), 365);
			}

			//X轴坐标
			for(int i=0; i<xAxisDatas.size(); i++) {
				xAxisDatas.set(i, xAxisDatas.get(i).substring(5, 10));
			}

			//处理金额  - 万转化为百万
			if(donelist.size()>0) {
				for(OrderCountVO od: donelist) {
					if(od.getCount() != 0) {
						od.setCount(od.getCount()/10000);
					}
				}
			}
			if(makelist.size()>0) {
				for(OrderCountVO od: makelist) {
					if(od.getCount() != 0) {
						od.setCount(od.getCount()/10000);
					}
				}
			}

			result.setAttribute("xAxisDatas", xAxisDatas);
			result.setAttribute("done", donelist);
			result.setAttribute("make", makelist);
			result.setAttribute("makeAll", makeAll);
			result.setAttribute("doneAll", doneAll);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

		}catch(Exception e){
			log.error("query productTimesCount error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	/**
	 * 金策师机构版 - 根据订单金额范围查询订单信息列表
	 * 
	 */
	@RequestMapping("/queryDoneByAmount")
	@ResponseBody
	public ResultMap queryDoneByAmount(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient){
		ResultMap result = new ResultMap();
		try{
			String amountType = request.getParameter("amountType");
			String uPhone = request.getParameter("uPhone");
			String orgid = request.getParameter("orgid");//机构ID
			String times = request.getParameter("times");//机构ID

			String userids = null;//要查询的人员id集合
			OrderDTO order = new OrderDTO();
			FpManagerOrder fpman = new FpManagerOrder();
			if(StringUtils.isBlank(amountType)||(StringUtils.isBlank(uPhone) && StringUtils.isBlank(orgid)) || StringUtils.isBlank(times)) {
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			} else {
				if(StringUtils.isNotBlank(orgid) && StringUtils.equals(orgid, "-1")) {
					orgid = null;
					userids = SessionUtil.getSession().getUser().getId();

					order.setCreateBy(userids);
				} else {
					userids = userInfoService.queryUseridByLayerPath(uPhone, orgid);//机构人员

					if(userids ==null) {
						order.setCreateBy(SessionUtil.getSession().getUser().getId());
					} else {
						if(userids.matches("\\d+")){//如果返回的手机号  需要查询userId
							UserInfoDTO userInfo =  new UserInfoDTO();
							userInfo.setTelePhone(userids);
							userInfo.setDeptflag(BizEnums.DeptType.PERSON);//人员
							userInfo.setStatus(0);
							UserInfoDTO queryUserInfo = userInfoService.queryUserInfo(userInfo);
							fpman.setsUid(queryUserInfo.getUserId());
						}else{
							fpman.setsUid(userids);
						}
					}
				}
			}

			if(!StringUtils.isBlank(times)){
				if(StringUtils.equals(times, "-1")) {//查全部订单
					order.setIsAll("true");//是否查全部
					times = null;
				} else {
					times= smp.format(TimesUtil.timsUpd(Integer.valueOf(times)));

					order.setCreateDateStr(times);//最小时间
				}
			}else{
				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(-6)));

				order.setCreateDateStr(times);//最小时间
			}

			order.setAllOrderStatus("220,240,310,320,330,360");   //只查询确认打款、待佣金到账

			WhereCondition wc = WC.one();
			if(StringUtils.equals(amountType, "100W_300W")) {
				wc.andGreaterEquals("a.O_AMOUNT", 1000000);
				wc.andLessThan("a.O_AMOUNT", 3000000);
			} else if(StringUtils.equals(amountType, "300W_1000W")) {
				wc.andGreaterEquals("a.O_AMOUNT", 3000000);
				wc.andLessThan("a.O_AMOUNT", 10000000);
			} else if(StringUtils.equals(amountType, "_1000W")) {
				wc.andGreaterEquals("a.O_AMOUNT", 10000000);
			} else {
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_TYPE_ERROR);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}

			List<OrderResVO> orderlist = orderService.queryOrderDoneByWherecondition(order, fpman, wc);
			for(OrderResVO od:orderlist) {
				//合同信息
				getContractStatusByOrderId(od);

				//报单状态
				getPhoStatusForOrderId(od);
			}

			result.setAttribute("orderlist", orderlist);

			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

		}catch(Exception e){
			log.error("query productTimesCount error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	//合同
	private void getContractStatusByOrderId(OrderResVO od) {
		try {
			FpFaUserContractDTO fpFaUserContract = new FpFaUserContractDTO();
			fpFaUserContract.setOrderId(od.getOrderId());
			fpFaUserContract = fpFaUserContractService.queryListGetFirst(fpFaUserContract);

			if(fpFaUserContract != null && StringUtils.isNotBlank(fpFaUserContract.getContractStatus())){
				od.setContractStatus(fpFaUserContract.getContractStatus());
				//			orderResultVO.setContractCode(fpFaUserContract.getContractCode());
				//			orderResultVO.setUserContract(fpFaUserContract);
			}

			if(StringUtils.isBlank(od.getContractStatus())){
				od.setContractStatus(Constants.UserContractDTO.STATUS_CONTRACT_01);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	//报单状态
	private void getPhoStatusForOrderId(OrderResVO orderResVO) {

		FpOrderPhoDTO fpd=new FpOrderPhoDTO();
		fpd.setoId(orderResVO.getOrderId());
		List<FpOrderPhoDTO> PODList=productOrderDataService.findProductOrderPhos(fpd);

		String phoStatus = Constants.order_data_pho_rev_no;
		Map<String,String> map = new HashMap<String,String>();
		for(FpOrderPhoDTO PODtmp  : PODList){
			if(StringUtils.isBlank(PODtmp.getoPhoStatus())){
				map.put("01", "01");
				continue;
			}
			map.put(PODtmp.getoPhoStatus(), "01");
		}

		if(map.containsKey(Constants.order_data_pho_rev_no)){
			phoStatus = Constants.order_data_pho_rev_no;
			orderResVO.setPhoStatus(phoStatus);
		}else if(map.containsKey(Constants.order_data_pho_rev_fail)){
			phoStatus = Constants.order_data_pho_rev_fail;
			orderResVO.setPhoStatus(phoStatus);
		}else if(map.containsKey(Constants.order_data_pho_rev_yes) ){
			phoStatus = Constants.order_data_pho_rev_yes;
			orderResVO.setPhoStatus(phoStatus);
		}else if(map.containsKey(Constants.order_data_pho_rev_success) && !map.containsKey(Constants.order_data_pho_rev_yes)){
			phoStatus = Constants.order_data_pho_rev_success;
			orderResVO.setPhoStatus(phoStatus);
		}else{
			//默认
			orderResVO.setPhoStatus(phoStatus);
		}
	}

	/***
	 * 

	 * @Title: listFpPhoneClientVist

	 * @Description: 访问量

	 * @param @param request
	 * @param @param fpPhoneClient
	 * @param @param pager
	 * @param @return    设定文件

	 * @return ResultMap    返回类型

	 * @throws
	 */
	@RequestMapping("/listFpPhoneClientVist")
	@ResponseBody
	public ResultMap listFpPhoneClientVist(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient,Pager pager){
		ResultMap result = new ResultMap();

		try{
			logger.info("query listFpPhoneClientVist list begin .......");
			List<Map<String,String>> resultList=new ArrayList<Map<String,String>>();
			result.setAttribute("list", resultList);
			UserDTO user = SessionUtil.getSession().getUser();
			String userid = user.getId();
			String phone=user.getLoginName();
			fpPhoneClient.setUserId(userid);
			result.setAttribute("pager", pager);
			//查询mongodb 用户访问店铺记录   
			String format=MessageFormat.format(shopRecord,phone,pager.getPageSize(),pager.getPageNo());
			String u=mongodbUrl+format;
			JSONObject json = getMongoDB(u);
			JSONArray list=new JSONArray();
			try {
				list = json.getJSONArray("list");
			} catch (Exception e) {
				logger.info("getJSONArray list is null");
				result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
				result.setStatus(ResultMap.STATUS.SUCCESS);
				return result;
			}
			JSONObject p=json.getJSONObject("pager");
			if(p!=null&&!p.isEmpty()){
				result.setAttribute("pager", p);
			}
			FpPhoneClientDTO fct=new FpPhoneClientDTO();
			fct.setUserId(userid);
			for (Object object : list) {
				JSONObject j=(JSONObject)object;
				Object wechatIdObject = j.get("wechatId");
				if(wechatIdObject == null){
					continue;
				}
				String wechatId=String.valueOf(wechatIdObject+"");
				fct.setWeixinAppid(wechatId);
				//查询用户昵称+是否已经添加微信客户
				Map<String, String> queryWechatAndFlagAdd = fpPhoneClientService.queryWechatAndFlagAdd(fct);

				if(queryWechatAndFlagAdd == null || StringUtils.isBlank(queryWechatAndFlagAdd.get("photo"))){

					continue;
				}
				String photo = queryWechatAndFlagAdd.get("photo");

				queryWechatAndFlagAdd.put("weixinAppid", wechatId);
				queryWechatAndFlagAdd.put("createDate", j.getString("createDate"));

				queryWechatAndFlagAdd.put("photo",photo.replaceAll("/0$","/64"));

				resultList.add(queryWechatAndFlagAdd);

			}
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

			logger.info("query listFpPhoneClientVist list end .......");
		}catch(Exception e){
			log.error("query listFpPhoneClientVist error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	/***
	 * 

	 * @Title: detailFpPhoneClientVist

	 * @Description: 访问客户详情

	 * @param @param request
	 * @param @param fpPhoneClient
	 * @param @param pager
	 * @param @return    设定文件

	 * @return ResultMap    返回类型

	 * @throws
	 */
	@RequestMapping("/detailFpPhoneClientVist")
	@ResponseBody
	public ResultMap detailFpPhoneClientVist(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient,Pager pager){
		ResultMap result = new ResultMap();

		try{
			logger.info("query detailFpPhoneClientVist list begin .......");
			UserDTO user = SessionUtil.getSession().getUser();
			String userid = user.getId();
			String phone=user.getLoginName();
			fpPhoneClient.setUserId(userid);
			result.setAttribute("pager", pager);
			String wechatId=request.getParameter("weixinAppid");
			if(StringUtils.isBlank(wechatId)){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			//查询mongodb 用户访问店铺记录   
			String format = MessageFormat.format(wapData,phone,wechatId,pager.getPageSize(),pager.getPageNo());
			String u=mongodbUrl+format;
			JSONObject json = getMongoDB(u);
			List<Map<String,String>> resultList=new ArrayList<Map<String,String>>();
			JSONArray list=new JSONArray();
			try {
				list = json.getJSONArray("list");
			} catch (Exception e) {
				logger.info("getJSONArray list is null");
				result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
				result.setStatus(ResultMap.STATUS.SUCCESS);
				return result;
			}
			JSONObject p=json.getJSONObject("pager");
			if(p!=null&&!p.isEmpty()){
				result.setAttribute("pager", p);
			}
			for (Object object : list) {
				JSONObject j=(JSONObject)object;
				Object type = j.get("type");
				Object pId=j.get("param");
				try {
					Map<String,String> m=new HashMap<String, String>();
					m.put("createDate", j.get("createDate")+"");
					if(type.equals("110204")){//基金
						FpFundInfoDTO fund = fpFundInfoService.loadById(Integer.parseInt(pId+""));
						if(fund.getId()!=null){
							m.put("name", fund.getJjmc());
							m.put("status", fund.getPubStatus());//1上架 0下架
							m.put("type","01");//基金类型
							resultList.add(m);
						}
					}else if(type.equals("110301")){//活动详情
						//查询活动名字
						Object activityId=j.get("activityId");
						if(activityId!=null){
							FpClientActivityDTO activity = fpClientActivityService.loadById(Integer.parseInt(activityId+""));
							if(StringUtils.isNotBlank(activity.getActivityTitle())){
								m.put("name", activity.getActivityTitle());
							}else{
								m.put("name", "店铺活动详情");
							}
						}else{
							m.put("name", "店铺活动详情");
						}
						m.put("status","0");//1上架 0下架
						m.put("type","07");//活动详情
						resultList.add(m);
					}else if(type.equals("110300")){//活动列表
						m.put("name", "店铺活动列表");
						m.put("status","0");//1上架 0下架
						m.put("type","08");//基金类型
						resultList.add(m);
					}else if(type.equals("110100")){//访问店铺
						m.put("name", "理财师店铺");
						m.put("status","0");//1上架 0下架
						m.put("type","");//基金类型
						resultList.add(m);
					}else{//非基金
						ProductBasicInfoDTO queryBasicInfo = productService.queryAllProductBasicInfo(pId+"");
						if(queryBasicInfo!=null&&StringUtils.isNotBlank(queryBasicInfo.getName())){
							m.put("name", queryBasicInfo.getName());
							m.put("status", queryBasicInfo.getShowStatus());//1上架 0下架
							m.put("type","01");
						}else{
							if(j.get("productName")==null||StringUtils.isBlank(j.getString("productName"))||"null".equals(j.getString("productName"))){
								continue;
							}
							m.put("name", j.get("productName")+"");
							m.put("status", "0");//1上架 0下架
						}
						resultList.add(m);
					}
				} catch (Exception e) {
					logger.error("shopRecordDetail error",e);
				}
			}

			//查询访问用户的基本微信信息
			FpPhoneClientDTO fct=new FpPhoneClientDTO();
			fct.setUserId(userid);
			fct.setWeixinAppid(wechatId);
			Map<String, String> q = fpPhoneClientService.queryWechatAndFlagAdd(fct);
			result.setAttribute("userInfo", q);

			result.setAttribute("list", resultList);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

			logger.info("query detailFpPhoneClientVist list end .......");
		}catch(Exception e){
			log.error("query detailFpPhoneClientVist error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	public JSONObject getMongoDB(String u) throws MalformedURLException,
	IOException {
		URL url=new URL(u);
		URLConnection openConnection = url.openConnection();
		InputStream inputStream = openConnection.getInputStream();
		String res=IOUtils.toString(inputStream);
		res=res.replaceAll("attributes", "attribute");
		JSONObject json=JSONObject.fromObject(res);
		JSONObject attribute = json.getJSONObject("attribute");
		return attribute;
	}

	@RequestMapping("/listFpPhoneClient")
	@ResponseBody
	public ResultMap list(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient,Pager pager){
		ResultMap result = new ResultMap();

		try{
			logger.info("query fpPhoneClient list begin .......");
			String id = SessionUtil.getSession().getUser().getId();
			fpPhoneClient.setUserId(id);
			fpPhoneClient.setBegin(pager.getStartIndex());
			fpPhoneClient.setPageSize(pager.getPageSize());

			int count = fpPhoneClientService.queryListCount(fpPhoneClient);

			pager.setTotalCount(count);

			List<FpPhoneClientDTO> fpPhoneClientList = null;

			if(count > 0){
				fpPhoneClientList = fpPhoneClientService.queryList(fpPhoneClient);
			}else{
				fpPhoneClientList = Collections.emptyList();
			}
			result.setAttribute("pager", pager);
			result.setAttribute("list", fpPhoneClientList);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

			logger.info("query fpPhoneClient list end .......");
		}catch(Exception e){
			log.error("query fpPhoneClient error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}

		return result;
	}

	@RequestMapping("/addFpPhoneClient")
	@ResponseBody
	public ResultMap add(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient){
		ResultMap result = new ResultMap();

		try{
			logger.info("add fpPhoneClient  begin .......");

			DTOdateSetUtil.setCreateInfo(fpPhoneClient);
			DTOdateSetUtil.setUpdateInfo(fpPhoneClient);
			fpPhoneClient.setDeleteTag("1");
			String id = SessionUtil.getSession().getUser().getId();
			fpPhoneClient.setUserId(id);

			//判断必填字段
			String name=fpPhoneClient.getName();
			if(StringUtils.isBlank(name)){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			String cWeixinAppid = fpPhoneClient.getWeixinAppid();
			if(StringUtils.isBlank(cWeixinAppid)){
				fpPhoneClient.setResource(CommonConstantUtil.HAND_ADD_CLIENT);//手动添加
			}else{
				//判断是否已经添加该微信账户
				FpPhoneClientDTO d=new FpPhoneClientDTO();
				d.setWeixinAppid(cWeixinAppid);
				d.setDeleteTag("1");
				d.setResource(CommonConstantUtil.HAND_ADD_CLIENT);
				d.setUserId(id);
				FpPhoneClientDTO q = fpPhoneClientService.queryListGetFirst(d);
				if(q.getId()!=null){
					result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
					result.setStatus(ResultMap.STATUS.SUCCESS);
					return result;
				}

				fpPhoneClient.setResource(CommonConstantUtil.WECHAT_ADD_CLIENT);//微信添加
				//根据微信APPID  查询 微信信息
				FaUserWechatDTO faUserWechatDTO=new FaUserWechatDTO();
				faUserWechatDTO.setMpOpenid(cWeixinAppid);
				FaUserWechatDTO queryUserWechatInfo = userWehatService.queryUserWechatInfo(faUserWechatDTO);
				if(queryUserWechatInfo.getId()==null){
					result.setStatus(ResultMap.STATUS.ERROR);
					result.setStatusCode(ResultMap.STATUS_CODE_WECHAT_RELATION_ERROR);
					return result;
				}
				fpPhoneClient.setNickname(queryUserWechatInfo.getNickname());
				fpPhoneClient.setPhoto(queryUserWechatInfo.getHeadimgurl());
			}

			fpPhoneClientService.insert(fpPhoneClient);

			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

			logger.info("add fpPhoneClient list end .......");
		}catch(Exception e){
			log.error("add fpPhoneClient error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}

		return result;
	}


	@RequestMapping("/detailFpPhoneClient")
	@ResponseBody
	public ResultMap detail(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient){
		ResultMap result = new ResultMap();

		try{
			logger.info("query detail fpPhoneClient  begin .......");

			Integer id = fpPhoneClient.getId();
			String cWeixinAppid = fpPhoneClient.getWeixinAppid();
			if(id==null&&StringUtils.isBlank(cWeixinAppid)){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			//有微信Id  需要查询微信
			if(StringUtils.isNotBlank(cWeixinAppid)){
				//根据微信APPID  查询 微信信息
				FaUserWechatDTO faUserWechatDTO=new FaUserWechatDTO();
				faUserWechatDTO.setMpOpenid(cWeixinAppid);
				FaUserWechatDTO queryUserWechatInfo = userWehatService.queryUserWechatInfo(faUserWechatDTO);
				if(queryUserWechatInfo.getId()==null){
					result.setStatus(ResultMap.STATUS.ERROR);
					result.setStatusCode(ResultMap.STATUS_CODE_WECHAT_RELATION_ERROR);
					return result;
				}
				fpPhoneClient.setNickname(queryUserWechatInfo.getNickname());
				fpPhoneClient.setPhoto(queryUserWechatInfo.getHeadimgurl());
				result.setAttribute("dto",fpPhoneClient);
			}

			if(id!=null){
				FpPhoneClientDTO dto = fpPhoneClientService.loadById(id);
				result.setAttribute("dto",dto);
			}

			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

			logger.info("query detail fpPhoneClient  end .......");
		}catch(Exception e){
			log.error("query detail fpPhoneClient error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}

		return result;
	}

	@RequestMapping("/deleteFpPhoneClient")
	@ResponseBody
	public ResultMap delete(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient){
		ResultMap result = new ResultMap();

		try{
			logger.info("delete fpPhoneClient  begin .......");

			Integer id = fpPhoneClient.getId();

			if(id==null){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}

			fpPhoneClientService.delete(id);

			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

			logger.info("delete fpPhoneClient  end .......");
		}catch(Exception e){
			log.error("delete fpPhoneClient error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}

		return result;
	}

	@RequestMapping("/updateForceFpPhoneClient")
	@ResponseBody
	public ResultMap updateForce(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient){
		ResultMap result = new ResultMap();

		try{
			logger.info("updateForce fpPhoneClient  begin .......");

			Integer id = fpPhoneClient.getId();

			if(id==null){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}

			FpPhoneClientDTO pcDto = fpPhoneClientService.loadById(id);

			if(pcDto.getId()==null){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			//修改的字段
			Map<String, Object> m=getParameterMap(request);
			setClientInfoUpdate(fpPhoneClient, pcDto, m);

			DTOdateSetUtil.setUpdateInfo(pcDto);

			fpPhoneClientService.updateForce(pcDto);


			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

			logger.info("updateForce fpPhoneClient list end .......");
		}catch(Exception e){
			log.error("updateForce fpPhoneClient error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}

		return result;
	}
	//需要单个修改   如果没有传这个参数      不进行修改
	public void setClientInfoUpdate(FpPhoneClientDTO fpPhoneClient,
			FpPhoneClientDTO pcDto, Map<String, Object> m) {
		Object name = m.get("name");
		if(name!=null){
			pcDto.setName(fpPhoneClient.getName());
		}
		Object email = m.get("email");
		if(email!=null){
			pcDto.setEmail(fpPhoneClient.getEmail());
		}
		Object mobile = m.get("mobile");
		if(mobile!=null){
			pcDto.setMobile(fpPhoneClient.getMobile());
		}
		Object remark = m.get("remark");
		if(remark!=null){
			pcDto.setRemark(fpPhoneClient.getRemark());
		}
		Object companyName = m.get("companyName");
		if(companyName!=null){
			pcDto.setCompanyName(fpPhoneClient.getCompanyName());
		}
		Object profession = m.get("profession");
		if(profession!=null){
			pcDto.setProfession(fpPhoneClient.getProfession());
		}
		Object starlevel = m.get("starlevel");
		if(starlevel!=null){
			pcDto.setStarlevel(fpPhoneClient.getStarlevel());
		}
	}

	@RequestMapping("/listFpPhoneProduct")
	@ResponseBody
	public ResultMap listFpPhoneProduct(HttpServletRequest request, FpPhoneClientDTO fpPhoneClient,Pager pager){
		ResultMap result = new ResultMap();

		try{
			logger.info("query listFpPhoneClientVist list begin .......");
			UserDTO user = SessionUtil.getSession().getUser();
			String userid = user.getId();
			String phone=user.getLoginName();
			fpPhoneClient.setUserId(userid);
			//查询mongodb 用户访问店铺记录
			String format = MessageFormat.format(shopRecord,phone,pager.getPageSize(),pager.getPageNo());
			URL url=new URL(mongodbUrl+format);
			URLConnection openConnection = url.openConnection();
			InputStream inputStream = openConnection.getInputStream();
			String res=IOUtils.toString(inputStream);
			res=res.replaceAll("attributes", "attribute");
			JSONObject json=JSONObject.fromObject(res);
			JSONObject attribute = json.getJSONObject("attribute");
			JSONArray list = attribute.getJSONArray("list");

			List<Map<String,String>> resultList=new ArrayList<Map<String,String>>();
			FpPhoneClientDTO fct=new FpPhoneClientDTO();
			fct.setUserId(userid);
			for (Object object : list) {
				JSONObject j=(JSONObject)object;
				String wechatId = j.getString("wechatId");
				if(StringUtils.isBlank(wechatId))
					continue;
				fct.setWeixinAppid(wechatId);
				//查询用户昵称+是否已经添加微信客户
				Map<String, String> queryWechatAndFlagAdd = fpPhoneClientService.queryWechatAndFlagAdd(fct);
				if(queryWechatAndFlagAdd!=null){
					queryWechatAndFlagAdd.put("weixinAppid", wechatId);
					queryWechatAndFlagAdd.put("createDate", j.getString("createDate"));
					resultList.add(queryWechatAndFlagAdd);
				}
			}
			result.setAttribute("pager", pager);
			result.setAttribute("list", resultList);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);

			logger.info("query listFpPhoneClientVist list end .......");
		}catch(Exception e){
			log.error("query listFpPhoneClientVist error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}
	@RequestMapping("/statisticsShopViewCount")
	@ResponseBody
	public ResultMap shopViewCount(HttpServletRequest request, HttpServletResponse response, String shopId){

		ResultMap result = new ResultMap();
		try {
			String url = mongodbUrl+shopViewCount;
			url = MessageFormat.format(url,shopId);

			logger.info("goto url: "+url);

			String res = HttpClientUtil.getInstance().doGetRequest(url);
			JSONObject jsonObj = JSONObject.fromObject(res);

			jsonObj.put("statusCode",ResultMap.STATUS_CODE_SUCCESS);
			logger.info("goto url: "+jsonObj.toString());
			AjaxUtils.ajaxJson(response,jsonObj.toString());
			return null;
		}catch(Exception e) {
			logger.error("goto shopViewCount:",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	@RequestMapping("/statisticsShopProductRecord")
	@ResponseBody
	public ResultMap statisticsShopProductRecord(HttpServletRequest request, HttpServletResponse response, String shopId,Pager pager){

		ResultMap result = new ResultMap();
		try {
			//  判断是否需要查询 多个手机号   有值 就多个
			String isList=request.getParameter("isList");
			if(StringUtils.isNotBlank(isList)){
				String orgId=request.getParameter("orgid");
				String phone=request.getParameter("uPhone");
				String phoneList=userInfoService.queryPhoneLayerPath(phone,orgId);
				if(StringUtils.isNotBlank(phoneList)){
					shopId=phoneList;
				}
			}
			String times = request.getParameter("getTimes");  
			if(!StringUtils.isBlank(times)){
				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(times)));
			}else{
				times="";//传就全部
			}
			String url = mongodbUrl+shopProductRecord;

			url = MessageFormat.format(url,shopId,pager.getPageSize(),pager.getPageNo(),times);

			logger.info("goto url: "+url);

			String res = HttpClientUtil.getInstance().doGetRequest(url);

			logger.info("goto url res: "+res);
			JSONObject jsonObj = JSONObject.fromObject(res);
			try {
				//添加产品销售状态
				JSONObject attributes = jsonObj.getJSONObject("attributes");
				Object o = attributes.get("list");

				JSONArray list = null;
				if(o instanceof JSONObject && ((JSONObject) o).isNullObject()){
					list = new JSONArray();
				}else{
					list = attributes.getJSONArray("list");
				}

				for (Object object : list) {
					JSONObject j = (JSONObject)object;
					Object type = j.get("type");
					Object pId=j.get("param");
					if(type==null||pId==null||!(pId+"").matches("[0-9\\-a-zA-Z]+"))
						continue;

					if("110204".equals(type)){//基金
						FpFundInfoDTO fund = fpFundInfoService.loadById(Integer.parseInt(pId+""));

						if(fund.getId()!=null){
							logger.info("goto url productName: "+fund.getJjmc());
							j.put("status", fund.getPubStatus());//1上架 0下架
							j.put("productName", fund.getJjmc());//1上架 0下架
						}
					}else{//非基金
						ProductBasicInfoDTO queryBasicInfo = productService.queryAllProductBasicInfo(pId+"");
						if(queryBasicInfo!=null&&StringUtils.isNotBlank(queryBasicInfo.getName())){
							j.put("status", queryBasicInfo.getShowStatus());//1上架 0下架
							j.put("productName", queryBasicInfo.getName());//1上架 0下架
						}else{
							j.put("status", "0");//1上架 0下架
						}
					}
				}
			} catch (Exception e) {
				logger.error("statisticsShopProductRecord  analysis list error!",e);
			}

			jsonObj.put("statusCode",ResultMap.STATUS_CODE_SUCCESS);
			logger.info("goto url: "+jsonObj.toString());
			AjaxUtils.ajaxJson(response,jsonObj.toString());
			return null;
		}catch(Exception e) {
			logger.error("goto shopViewCount:",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	/***
	 * 20180426备注    店铺某产品浏览用户
	 * @param request
	 * @param response
	 * @param shopId
	 * @param pager
	 * @param param
	 * @param type
	 * @return
	 */
	@RequestMapping("/statisticsShopProductRecordDetail")
	@ResponseBody
	public ResultMap statisticsShopProductRecordDetail(HttpServletRequest request, HttpServletResponse response, String shopId,Pager pager,String param,String type){

		ResultMap result = new ResultMap();
		try {
			//参数为空
			if(StringUtils.isBlank(param) || StringUtils.isBlank(type) || StringUtils.isBlank(shopId)){
				result.setStatus(ResultMap.STATUS.ERROR);
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				return result;
			}

			//添加产品信息
			if(type==null||param==null||!(param).matches("[0-9\\-a-zA-Z]+")){
				result.setStatus(ResultMap.STATUS.ERROR);
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				return result;
			}

			//  判断是否需要查询 多个手机号   有值 就多个
			String isList=request.getParameter("isList");
			if(StringUtils.isNotBlank(isList)){
				String orgId=request.getParameter("orgid");
				String phone=request.getParameter("uPhone");
				String phoneList=userInfoService.queryPhoneLayerPath(phone,orgId);
				if(StringUtils.isNotBlank(phoneList)){
					shopId=phoneList;
				}
			}

			String times = request.getParameter("getTimes");  
			if(!StringUtils.isBlank(times)){
				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(times)));
			}else{
				times="";//传就全部
			}

			String url = mongodbUrl+shopProductRecordDetail;
			url = MessageFormat.format(url,shopId,param,pager.getPageSize(),pager.getPageNo(),times);
			logger.info("goto url: "+url);
			String res = HttpClientUtil.getInstance().doGetRequest(url);
			JSONObject jsonObj = JSONObject.fromObject(res);

			try{
				//添加产品销售状态
				JSONObject attributes = jsonObj.getJSONObject("attributes");
				if("110204".equals(type)){//基金
					FpFundInfoDTO fund = fpFundInfoService.loadById(Integer.parseInt(param));
					if(fund.getId()!=null){
						attributes.put("dto", fund);
					}
				}else{//非基金

					Integer id = productService.getProductIdByProductCode(param);
					if(id == null){
						logger.error("==>error message:product is not exists");

					}else {
						ProductDetailPageDTO productDTO = productService.getProductDetailView(id);

						if (productDTO != null && StringUtils.isNotBlank(productDTO.getProductName())) {
							attributes.put("dto", productDTO);
						}
					}
				}

				//添加 用户微信信息
				JSONArray list = attributes.getJSONArray("list");
				FaUserWechatDTO faUserWechatDTO = new FaUserWechatDTO();
				for (Object object : list) {
					JSONObject j = (JSONObject) object;
					Object wechatId = j.get("wechatId");
					faUserWechatDTO.setMpOpenid(wechatId.toString());
					FaUserWechatDTO view = userWehatService.queryUserWechatInfo(faUserWechatDTO);
					if(view != null){
						j.put("nickname",view.getNickname());
						j.put("headimgurl",view.getHeadimgurl());
					}
				}
			} catch (Exception c){
				logger.error("goto statisticsShopProductRecordDetail:",c);
			}

			jsonObj.put("statusCode",ResultMap.STATUS_CODE_SUCCESS);
			logger.info("goto url: "+jsonObj.toString());
			AjaxUtils.ajaxJson(response,jsonObj.toString());
			return null;
		}catch(Exception e) {
			logger.error("goto shopViewCount:",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	/**
	 *产品分享 列表
	 */
	@RequestMapping("/shareShopProductCount")
	@ResponseBody
	public ResultMap shareShopProductCount(HttpServletRequest request, HttpServletResponse response, FpPhoneClientDTO fpPhoneClient,Pager pager) {
		ResultMap result = new ResultMap();
		try{
			UserDTO user = SessionUtil.getSession().getUser();

			String productCode=request.getParameter("productCode");
			if(StringUtils.isBlank(productCode)){
				result.setStatus(ResultMap.STATUS.ERROR);
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				return result;
			}

			String orgId=request.getParameter("orgid");
			String phone=request.getParameter("uPhone");
			if(StringUtils.isBlank(phone) && StringUtils.isBlank(orgId) ) {
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			//  判断是否需要查询 多个手机号   有值 就多个
			//			String isList=request.getParameter("isList");
			//			if(StringUtils.isNotBlank(isList)){
			String phoneList=userInfoService.queryPhoneLayerPath(phone,orgId);
			if(StringUtils.isNotBlank(phoneList)){
				phone=phoneList;
			}
			//			}
			String times = request.getParameter("getTimes");  //查询时间 默认为7天 ，-1就全部
			if(!StringUtils.isBlank(times)){
				if(times.equals("-1")){
					times="";
				}else{
					times= smp.format(TimesUtil.timsUpd(Integer.valueOf(times)));
				}
			}else{
				//				times= smp.format(TimesUtil.timsUpd(Integer.valueOf(-7)));
				times="";
			}

			//查询店铺浏览量shopId={0}&monthStart={1}&pageNo={2}&pageSize={3}&param={4}
			String format=MessageFormat.format(shareShopProductCount,phone,times,pager.getPageSize(),pager.getPageNo(),productCode);
			String u=mongodbUrl+format;
			JSONObject json = getMongoDB(u);
			//添加 用户微信信息
			JSONArray list=new JSONArray();
			try {
				list = json.getJSONArray("list");
				for (Object object : list) {
					try {
						JSONObject j = (JSONObject) object;
						Object shopId = j.get("shopId");
						if(shopId==null){
							continue;
						}
						UserInfoDTO userInfoDTO=new UserInfoDTO();
						userInfoDTO.setTelePhone(shopId+"");
						UserInfoDTO queryUserInfo = userInfoService.queryUserInfo(userInfoDTO);
						if(queryUserInfo==null||StringUtil.isNullOrEmptyNStr(queryUserInfo.getUserNickname())){
							j.put("shopId", StringUtil.mobileHide4Number(shopId+""));
							//获取用户名
							ShopperUserInfoDTO shopperUserInfo=new ShopperUserInfoDTO();
							//用户id
							shopperUserInfo.setUserId(user.getId());
							ShopperUserInfoDTO shopperUserInfoDto = shopperUserInfoService.queryListGetFirst(shopperUserInfo);
							if(shopperUserInfoDto==null){
								j.put("userName", user.getuRealName());
							}else{
								j.put("userName", shopperUserInfoDto.getUserName());
							}
						}else{
							j.put("userName", queryUserInfo.getUsername());
							j.put("shopId", StringUtil.mobileHide4Number(shopId+""));
						}
					} catch (Exception e) {
						logger.error("shareShopProductCount error",e);
					}
				}
			} catch (Exception e) {
				logger.error("shareShopProductCount is null:",e);
			}
			result.setAttribute("list", list);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			return result;
		}catch(Exception e){
			log.error("query shopSeeCount error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

	/***
	 * 20180426备注    店铺某产品浏览用户 新增
	 * @param request
	 * @param response
	 * @param shopId
	 * @param pager
	 * @param param
	 * @param type
	 * @return
	 */
	@RequestMapping("/shopProductSeeDetail")
	@ResponseBody
	public ResultMap shopProductSeeDetail(HttpServletRequest request, HttpServletResponse response,Pager pager,String param,String type){

		ResultMap result = new ResultMap();
		try {
			UserDTO user = SessionUtil.getSession().getUser();
			String shopId=user.getLoginName();
			//参数为空
			if(StringUtils.isBlank(param) || StringUtils.isBlank(type)){
				result.setStatus(ResultMap.STATUS.ERROR);
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				return result;
			}

			//添加产品信息
			if(type==null||param==null||!(param).matches("[0-9\\-a-zA-Z]+")){
				result.setStatus(ResultMap.STATUS.ERROR);
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				return result;
			}

			String times = request.getParameter("getTimes");  
			if(!StringUtils.isBlank(times)){
				if(times.equals("-1")){
					times="";
				}else{
					times= smp.format(TimesUtil.timsUpd(Integer.valueOf(times)));
				}
			}else{
				times= "";
			}
			//wapData/shopProductSeeDetail?shopId={0}&monthStart={1}&pageNo={2}&pageSize={3}&param={4}
			String url = mongodbUrl+shopProductSeeDetail;
			url = MessageFormat.format(url,shopId,times,pager.getPageSize(),pager.getPageNo(),param);
			logger.info("goto url: "+url);
			String res = HttpClientUtil.getInstance().doGetRequest(url);
			JSONObject jsonObj = JSONObject.fromObject(res);
			try{
				//添加产品销售状态
				JSONObject attributes = jsonObj.getJSONObject("attributes");
				//添加 用户微信信息
				JSONArray list = new JSONArray();
				
				if(attributes.get("list")!=null){
					list = attributes.getJSONArray("list");
				}
				for (Object object : list) {
					try {
						JSONObject j = (JSONObject) object;
						Object wechatId = j.get("wechatId");
						FaUserWechatDTO faUserWechatDTO = new FaUserWechatDTO();
						faUserWechatDTO.setAllOpenId(wechatId.toString());
						FaUserWechatDTO view = userWehatService.queryUserWechatInfo(faUserWechatDTO);
						
						if(view != null){
							j.put("nickname",view.getNickname());
							j.put("headimgurl",view.getHeadimgurl());
							String userId = view.getUserId();
							CorpFaUserDTO u = userService.getUserById(userId);
							if(u!=null){
								j.put("uLoginName", u.getuLoginName());
								j.put("userName", u.getuRealName());
							}
						
						}
					} catch (Exception e) {
						logger.error("goto faUserWechatDTO error:",e);
					}
				}
			} catch (Exception c){
				logger.error("goto statisticsShopProductRecordDetail:",c);
			}

			jsonObj.put("statusCode",ResultMap.STATUS_CODE_SUCCESS);
			logger.info("goto url: "+jsonObj.toString());
			AjaxUtils.ajaxJson(response,jsonObj.toString());
			return null;
		}catch(Exception e) {
			logger.error("goto shopViewCount:",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}

}
